﻿namespace Huayou.UI.WebControls
{
    using System;
    using System.Web.UI;
    using System.Xml;

    internal abstract class MenuItemRenderBase : MenuItem
    {
        public MenuItemRenderBase(XmlElement node, MenuGroup parentGroup, WebMenu menu) : base(node, parentGroup, menu)
        {
        }

        protected string generateClickCommand()
        {
            string postBackClientHyperlink = "";
            string str2 = "";
            string redirectURL = "";
            if (base.IsDisabled)
            {
                return "";
            }
            if (base.ClientSideOnClick != null)
            {
                return ("aspnm_hideAllGroups();" + base.ClientSideOnClick);
            }
            if (base.URL != null)
            {
                if (base.URLAbsolute)
                {
                    redirectURL = base.URL;
                }
                else
                {
                    redirectURL = base.Menu.BaseURL + base.URL;
                }
                if (base.URLTarget != null)
                {
                    str2 = "aspnm_hideAllGroups();top." + base.URLTarget + ".document.location.href='" + redirectURL + "';";
                }
                else
                {
                    str2 = "document.location.href='" + redirectURL + "';";
                }
            }
            if ((base.URL != null) && (base.ID == null))
            {
                postBackClientHyperlink = str2;
            }
            else if ((base.URL == null) && (base.ID != null))
            {
                postBackClientHyperlink = base.Menu.Page.GetPostBackClientHyperlink(base.Menu, base.ID);
            }
            else if ((base.URL != null) && (base.ID != null))
            {
                if (this.isCurrentURL(redirectURL))
                {
                    postBackClientHyperlink = base.Menu.Page.GetPostBackClientHyperlink(base.Menu, base.ID);
                }
                else
                {
                    postBackClientHyperlink = str2;
                }
            }
            if (postBackClientHyperlink.StartsWith("javascript:"))
            {
                postBackClientHyperlink = postBackClientHyperlink.Replace("javascript:", "");
                if (base.CausesValidation)
                {
                    postBackClientHyperlink = "{aspnm_hideAllGroups(); if (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate()) " + postBackClientHyperlink + "}";
                }
            }
            return postBackClientHyperlink;
        }

        protected string getCollapseEffect()
        {
            return "null";
        }

        protected string getExpandEffect()
        {
            string str = "null";
            string str2 = (((float) base.Menu.EffectDuration) / 1000f).ToString();
            if (base.Menu.supportEffects())
            {
                if (base.ItemNode.ChildNodes[0].Attributes["ExpandEffect"] != null)
                {
                    switch (base.ItemNode.ChildNodes[0].Attributes["ExpandEffect"].Value.ToLower())
                    {
                        case "none":
                            return "null";

                        case "dissolve":
                            return ("'revealTrans(transition=12, duration=" + str2 + ")'");

                        case "fade":
                            return ("'progid:DXImageTransform.Microsoft.Fade(overlap=1.0, duration=" + str2 + ")'");

                        case "inset":
                            return ("'progid:DXImageTransform.Microsoft.Inset(duration=" + str2 + ")'");

                        case "pixelate":
                            return ("'progid:DXImageTransform.Microsoft.Pixelate(maxsquare=15, duration=" + str2 + ")'");

                        case "random":
                            return ("'revealTrans(transition=24, duration=" + str2 + ")'");

                        case "squareiris":
                            return ("'revealTrans(transition=1, duration=" + str2 + ")'");

                        case "stretchleftright":
                            return ("'progid:DXImageTransform.Microsoft.Stretch(duration=" + str2 + ")'");

                        case "stretchtopdown":
                            return ("'revealTrans(transition=16, duration=" + str2 + ")'");
                    }
                    return str;
                }
                switch (base.Menu.ExpandEffect)
                {
                    case WebMenuEffect.Fade:
                        return ("'progid:DXImageTransform.Microsoft.Fade(overlap=1.0, duration=" + str2 + ")'");

                    case WebMenuEffect.Inset:
                        return ("'progid:DXImageTransform.Microsoft.Inset(duration=" + str2 + ")'");

                    case WebMenuEffect.Pixelate:
                        return ("'progid:DXImageTransform.Microsoft.Pixelate(maxsquare=15, duration=" + str2 + ")'");

                    case WebMenuEffect.StretchLeftRight:
                        return ("'progid:DXImageTransform.Microsoft.Stretch(duration=" + str2 + ")'");

                    case WebMenuEffect.StretchTopDown:
                        return ("'revealTrans(transition=16, duration=" + str2 + ")'");

                    case WebMenuEffect.Dissolve:
                        return ("'revealTrans(transition=12, duration=" + str2 + ")'");

                    case WebMenuEffect.SquareIris:
                        return ("'revealTrans(transition=1, duration=" + str2 + ")'");

                    case WebMenuEffect.Random:
                        return ("'revealTrans(transition=24, duration=" + str2 + ")'");

                    case WebMenuEffect.None:
                        return str;
                }
            }
            return str;
        }

        private bool isCurrentURL(string RedirectURL)
        {
            bool flag = false;
            if (RedirectURL.ToLower() == base.Menu.Page.Request.Url.AbsoluteUri.ToLower())
            {
                flag = true;
            }
            if ((base.Menu.Page.Request.Url.GetLeftPart(UriPartial.Authority).ToLower() + base.Menu.Page.Request.ApplicationPath.ToLower() + "/" + RedirectURL.ToLower()) == base.Menu.Page.Request.Url.AbsoluteUri.ToLower())
            {
                flag = true;
            }
            return flag;
        }

        public void Render(HtmlTextWriter output)
        {
            if (base.Image != null)
            {
                this.RenderImageItem(output);
            }
            else if ((base.LeftIcon != null) || (base.RightIcon != null))
            {
                this.RenderIconItem(output);
            }
            else if (((base.ParentGroup.MaxLeftIconWidth > 0) || (base.ParentGroup.MaxRightIconWidth > 0)) && (base.ParentGroup.Orientation == "vertical"))
            {
                this.RenderIconItem(output);
            }
            else
            {
                this.RenderCssItem(output);
            }
        }

        public abstract void RenderCssItem(HtmlTextWriter output);
        public abstract void RenderIconItem(HtmlTextWriter output);
        public abstract void RenderImageItem(HtmlTextWriter output);
    }
}

